package com.spring.hot;

/**
 * @author Cizai
 * @since 2022/12/10 11:58
 **/
public class 最大子数组和 {

    public int maxSubArray(int[] nums) {

        if (nums.length == 1) return nums[0];

        int result = nums[0];
        int sum = 0;
        for (int i = 0; i < nums.length; i++) {
            if (sum > 0) sum+=nums[i];
            else sum = nums[i];
            result = Math.max(result, sum);
        }
        return result;
    }

}
